<template>
  <div>
    <a-spin :spinning="loading">
      <top-nav-bar :applyPageRoute="printtitle" @back="back"></top-nav-bar>
      <a-card :bordered="false" style="margin-top:15px">
        <a-button
          style="margin-right:15px"
          type="primary"
          @click="showModal"
          v-if="receiptList.real_price-receiptList.receivable<0&&receiptList.type!=3"
        >补交</a-button>
        <!-- <a-button type="primary" @click="showModal">补交</a-button> -->
        <a-button
          style="margin-right:15px"
          @click="showDeleteConfirm(receiptList.id)"
          v-if="receiptList.type!=3"
        >作废订单</a-button>
        <a-button @click="goreceipt" v-if="receiptList.type!=3" style="margin-right:15px">打印收据</a-button>
        <a-button @click="actionDay(receiptList.id)" style="margin-right:15px">操作日志</a-button>
        <div style="margin-top:20px;position:relative">
          <div style="position: absolute;z-index: 999;right: 0;top: -6px;width: 80px;height: 80px;">
            <img
              src="~@/assets/img/order/makeup.png"
              v-if="receiptList.real_price-receiptList.receivable<0&&receiptList.type!=3"
              style="width:100%;"
            />
            <img
              src="~@/assets/img/order/payed.png"
              v-else-if="receiptList.real_price-receiptList.receivable<=0&&receiptList.type!=3"
              style="width:100%;"
            />
            <img
              src="~@/assets/img/order/feichu.png"
              v-else-if="receiptList.type==3"
              style="width:100%;"
            />
          </div>
          <div
            class="ant-row title"
            style="font-size:16px;margin-bottom:5px;"
          >订单编号： {{receiptList.order_no}}</div>
          <p class="order-info">
            <span>创建时间：{{receiptList.created_at}}</span>
            <span>
              订单类型：
              <span v-if="receiptList.order_type==1">报名</span>
              <span v-if="receiptList.order_type==2">退费用</span>
              <span v-if="receiptList.order_type==3">退物品</span>
              <span v-if="receiptList.order_type==4">退课</span>
              <span v-if="receiptList.order_type==5">转课</span>
            </span>
            <span>订单来源：{{receiptList.source_type==1?'机构创建':'导入订单'}}</span>
          </p>
          <a-list :grid="{ gutter: 16, column: 1 }" :data-source="data">
            <a-list-item slot="renderItem" slot-scope="item,index">
              <!-- :title="item.title" -->
              <a-card>
                <div class="ant-col ant-col-8">
                  <div class="basic-item" v-if="receiptList.student">
                    <p>
                      <span>学员姓名：</span>
                      <span>{{receiptList.student.name}}</span>
                    </p>
                    <p>
                      <span>性别：</span>
                      <span>{{receiptList.student.sex==1?'男':'女'}}</span>
                    </p>
                    <p>
                      <span>手机号：</span>
                      <span>{{receiptList.student.main_phone}}</span>
                    </p>
                  </div>
                </div>
                <div class="ant-col ant-col-8">
                  <div class="basic-item" v-if="receiptList.order_type==1">
                    <p>
                      <span>应收金额：</span>
                      <span v-if="receiptList.receivable">￥{{receiptList.receivable}}</span>
                    </p>
                    <p>
                      <span>实收金额：</span>
                      <span
                        v-if="receiptList.real_price"
                      >￥{{Number(receiptList.real_price)-Number(receiptList.bad_debt)}}</span>
                    </p>
                    <p v-if="receiptList.real_price&&receiptList.receivable">
                      <span v-if="Number(receiptList.real_price)!==Number(receiptList.receivable)">
                        <span>欠费金额：</span>

                        <span
                          style="color: rgb(255, 79, 79);"
                        >￥{{receiptList.receivable-receiptList.real_price>0?(receiptList.receivable*1000000-receiptList.real_price*1000000)/1000000:'0'}}</span>
                        <!-- js精确小数 -->
                        <a
                          @click="badorder(receiptList)"
                          style="margin-left:8px;"
                          v-if="receiptList.real_price-receiptList.receivable<0"
                        >标记为坏账</a>
                      </span>
                    </p>
                    <p v-if="receiptList.bad_debt&&receiptList.bad_debt!==null">
                      <span>坏账金额：</span>
                      <span>￥{{receiptList.bad_debt}}</span>
                    </p>
                  </div>
                  <div
                    v-else-if="receiptList.order_type==5&&receiptList.refunds[0].total_amount-transferInSum<0"
                  >
                    <p>
                      <span>应收金额：</span>
                      <span v-if="receiptList.receivable">￥{{receiptList.receivable}}</span>
                    </p>
                    <p>
                      <span>实收金额：</span>
                      <span
                        v-if="receiptList.real_price"
                      >￥{{Number(receiptList.real_price)-Number(receiptList.bad_debt)}}</span>
                    </p>
                    <p v-if="receiptList.real_price&&receiptList.receivable">
                      <span v-if="Number(receiptList.real_price)!==Number(receiptList.receivable)">
                        <span>欠费金额：</span>

                        <span
                          style="color: rgb(255, 79, 79);"
                        >￥{{receiptList.receivable-receiptList.real_price>0?(receiptList.receivable*1000000-receiptList.real_price*1000000)/1000000:'0'}}</span>
                        <!-- js精确小数 -->
                        <a
                          @click="badorder(receiptList)"
                          style="margin-left:8px;"
                          v-if="receiptList.real_price-receiptList.receivable<0"
                        >标记为坏账</a>
                      </span>
                    </p>
                  </div>
                  <div v-else>
                    <p>
                      <span>应退金额：</span>
                      <span v-if="receiptList.receivable">￥{{Math.abs(receiptList.receivable)}}</span>
                    </p>
                    <p>
                      <span>实退金额：</span>
                      <span
                        v-if="receiptList.real_price"
                      >￥{{Number(receiptList.real_price)-Number(receiptList.bad_debt)}}</span>
                    </p>
                  </div>
                </div>
                <div class="ant-col ant-col-8">
                  <div class="basic-item">
                    <p>
                      <span>经办日期：</span>
                      <span v-if="receiptList.purchase_at">{{receiptList.purchase_at|dayjs}}</span>
                    </p>
                    <p>
                      <span>经办人：</span>
                      <span v-if="receiptList.operator">{{receiptList.operator}}</span>
                    </p>
                    <p>
                      <span>业绩归属人：</span>
                      <span class="achievement">
                        <a-tooltip placement="topLeft" v-if="receiptList.user_name">
                          <template slot="title">{{receiptList.user_name}}</template>
                          {{receiptList.user_name}}
                        </a-tooltip>
                        <span v-else>-</span>
                      </span>
                      <a
                        class="edit-btn"
                        @click="user_name_visible=true"
                        v-if="receiptList.type!=3"
                      >修改</a>
                    </p>
                    <p>
                      <span>备注：</span>
                      <span class="leave-msg">
                        <a-tooltip placement="topLeft" v-if="receiptList.remarks">
                          <template slot="title">{{receiptList.remarks}}</template>
                          {{receiptList.remarks}}
                        </a-tooltip>
                        <span v-else>-</span>
                      </span>
                      <a class="edit-btn" @click="remarksEdit" v-if="receiptList.type!=3">编辑</a>
                    </p>
                  </div>
                </div>
              </a-card>
            </a-list-item>
          </a-list>
        </div>
        <a-modal
          title="操作日志"
          :visible="action_visible"
          :confirm-loading="action_confirmLoading"
          @cancel="actionCanl"
          :width="680"
          :footer="null"
        >
          <a-table
            :columns="acitonColumns"
            :data-source="actionData"
            :rowKey="actionData => actionData.id"
            :scroll="{ y: 340 }"
            :pagination="pagination"
            @change="handleTableChange"
            :loading="tableloading"
            class="user_management_table"
            style="border:1px solid #e8e8e8"
          >
            <span slot="updated_at" slot-scope="text,record">{{record.updated_at|formatDate()}}</span>
            <span slot="content" slot-scope="text,record">
              <span v-if="record.event=='修改业绩归属人'">{{record.content}}</span>
              <span v-else>-</span>
            </span>
          </a-table>
          <!-- <s-table
            ref="table"
            size="default"
            rowKey="key"
            :columns="acitonColumns"
            :data="actionData"
            :scroll="{ y: 240 }"
            class="user_management_table"
          >
          
          </s-table>-->
        </a-modal>
        <a-modal
          title="修改业绩归属人"
          :visible="user_name_visible"
          :confirm-loading="user_name_confirmLoading"
          @ok="user_name_remarks(1)"
          @cancel="user_name_visible=false"
        >
          <a-alert type="info" :message="description" class="a-alert" banner />
          <div style="margin-top:20px">
            <span style="padding-right:10px">业绩归属人:</span>
            <a-select
              placeholder="请选择业绩归属人"
              mode="multiple"
              v-model="user_ids"
              style="width:200px;margin-right:10px;"
            >
              <a-select-option
                v-for="(item,index) in userSelect"
                :key="index"
                :value="item.user_school_id"
              >{{item.name}}</a-select-option>
            </a-select>
          </div>
        </a-modal>

        <a-modal
          title="编辑备注"
          :visible="remarks_visible"
          :confirm-loading="remarks_confirmLoading"
          @ok="user_name_remarks(2)"
          @cancel="remarks_visible=false"
        >
          <a-textarea
            class="textarea_remark"
            v-model="newremarks"
            placeholder="请输入备注(最多100个字符)"
            :maxLength="100"
          ></a-textarea>
        </a-modal>
        <!-- 作废信息 -->
        <div v-if="receiptList.type==3" style="margin-bottom:20px;">
          <p class="ant-row title">作废信息</p>
          <div class="ant-row">
            <a-table
              :columns="voidLog_columns"
              :data-source="voidLog"
              :pagination="false"
              class="user_management_table"
              style="border:1px solid #e8e8e8"
            >
              <span slot="created_at" slot-scope="text,record">{{record.created_at|formatDate}}</span>
              <span slot="type" slot-scope="text,record">
                <span v-if="record.type==1">重复录入</span>
                <span v-if="record.type==2">信息填错</span>
                <span v-if="record.type==3">其他</span>
              </span>
            </a-table>
          </div>
        </div>
        <div v-if="receiptList.order_type==1">
          <div style="margin-bottom:20px;">
            <p class="ant-row title">购买内容</p>
            <div class="ant-row">
              <a-table
                :columns="columns"
                :data-source="shopList"
                :pagination="false"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
              >
                <span slot="projectName" slot-scope="text,record">
                  <span>{{record.project.name}}</span>
                  <span v-if="record.project_type==1" style="margin-left:5px;">
                    <a-tag color="orange">
                      <span v-if="record.course_type==0">购买</span>
                      <span v-if="record.course_type==1">新报</span>
                      <span v-if="record.course_type==2">续报</span>
                      <span v-if="record.course_type==3">扩科</span>
                    </a-tag>
                  </span>
                </span>
                <span slot="unit_price" slot-scope="text,record">
                  <span v-if="record.project_type==1">
                    <span v-if="record.price_type==1">￥{{record.unit_price}}/课时</span>
                    <span v-if="record.price_type==2">￥{{record.unit_price}}/天</span>
                  </span>
                  <span v-else-if="record.project_type==2">￥{{record.unit_price}}/件</span>
                  <span v-else-if="record.project_type==3">￥{{record.unit_price}}/笔</span>
                </span>
                <span slot="classhours" slot-scope="text,record">
                  <span v-if="record.project_type==1">
                    <span v-if="record.price_type==1">{{record.buy_number}}课时</span>
                    <span
                      v-if="record.price_type==2"
                    >{{record.buy_start_time}}至{{record.buy_end_time}}</span>
                  </span>
                  <span v-else-if="record.project_type==2">{{record.buy_number}}件</span>
                  <span v-else-if="record.project_type==3">{{record.buy_number}}笔</span>
                </span>
                <span slot="courseMoney" slot-scope="text,record">
                  <!-- <span>￥{{record.buy_number*record.unit_price}}</span> -->

                  <span v-if="record.signing_price">
                    ￥{{record.buy_number*record.unit_price}}
                    <!-- <span v-if="record.discount">
                      <span
                        v-if="JSON.parse(record.discount).type==1"
                      >{{Number(record.signing_price)+Number(JSON.parse(record.discount).value)}}</span>
                      <span v-else-if="JSON.parse(record.discount).type==2">
                        {{Number(record.signing_price)/(JSON.parse(record.discount).value/10)}}
                        
                      </span>
                    </span> -->
                  </span>
                  <span v-else>--</span>
                </span>

                <span slot="giveclasshours" slot-scope="text,record">
                  <span v-if="record.project_type==1">
                    <span v-if="record.give_number!=0">
                      <span v-if="record.price_type==1">{{record.give_number}}</span>
                      <span
                        v-else-if="record.price_type==2&&record.give_number!=0"
                      >至{{record.month_buy_end_time}}</span>
                    </span>
                    <span v-else>-</span>
                  </span>

                  <span v-if="record.project_type==2">
                    <span v-if="record.give_number!=0">{{record.give_number}}</span>
                    <span v-else>-</span>
                  </span>

                  <span v-if="record.project_type==3">
                    <span v-if="record.give_number!=0">{{record.give_number}}</span>
                    <span v-else>-</span>
                  </span>
                </span>

                <span slot="moneyDiscount" slot-scope="text,record">
                  <span v-if="record.discount">
                    <span
                    v-if="JSON.parse(record.discount).type==1&&JSON.parse(record.discount).value!=0"
                  >￥{{JSON.parse(record.discount).value}}</span>
                  <span
                    v-else-if="JSON.parse(record.discount).type==2&&JSON.parse(record.discount).value!=0"
                  >{{JSON.parse(record.discount).value?JSON.parse(record.discount).value+'折':'-'}}</span>
                  </span>
                  <span v-else>-</span>
                </span>
                <!-- 优惠/折扣：例{"type":1,"value":"100"}     type为1直减，2折扣     value为值 -->
                <span slot="signing_price" slot-scope="text,record">
                  <!-- <span v-if="record.signing_price&&record.discount&&JSON.parse(record.discount).value!=0">
                    ￥
                      <span
                        v-if="JSON.parse(record.discount).type==1"
                      >{{Number(record.signing_price)-JSON.parse(record.discount).value}}</span>
                      <span
                        v-else-if="JSON.parse(record.discount).type==2"
                      >{{Number(record.signing_price)*(JSON.parse(record.discount).value/10)}}</span>
                  </span>
                  <span v-else-if="record.signing_price&&!record.discount">{{record.signing_price}}</span> -->
                  <span v-if="record.signing_price&&record.discount">{{record.signing_price}}</span>
                  <span v-else>-</span>
                </span>
              </a-table>
            </div>
          </div>
          <div>
            <p class="ant-row title">支付记录</p>
            <div class="ant-row">
              <a-table
                ref="table"
                :columns="columns1"
                :data-source="orderHistory"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
                :pagination="false"
              >
                <span slot="purchase_at" slot-scope="text,record">{{record.purchase_at|dayjs}}</span>
                <span slot="type" slot-scope="text,record">
                  <span v-if="record.type==1">报名/续费</span>
                  <span v-if="record.type==2">手续费</span>
                  <span v-if="record.type==3">补交</span>
                  <span v-if="record.type==4">坏账</span>
                  <span v-if="record.type==5">亏损费</span>
                  <span v-if="record.type==6">转课</span>
                  <span v-if="record.type==7">-</span>
                  <span v-if="record.type==8">退课</span>
                  <span v-if="record.type==9">退物品</span>
                  <span v-if="record.type==10">退费用</span>
                </span>
                <div slot="charge_type" slot-scope="text,record">
                  <div v-for="(item,index) in record.prices" :key="index">
                    <div v-if="item.charge_type!=0">
                      <div v-if="item.charge_type==1">支付方式：支付宝</div>
                      <div v-if="item.charge_type==2">支付方式：微信</div>
                      <div v-if="item.charge_type==3">支付方式：现金</div>
                      <div v-if="item.charge_type==4">支付方式：网银</div>
                      <div v-if="item.charge_type==5">支付方式：pos机</div>
                    </div>
                    <div style="margin:5px 0;">收款金额：￥{{item.price}}</div>
                  </div>
                </div>
                <span slot="status" slot-scope="text,record">
                  <span v-if="record.status==1">收款成功</span>
                  <span v-else>收款失败</span>
                </span>
              </a-table>
            </div>
          </div>
        </div>
        <!-- 转课 -->
        <div v-if="receiptList.order_type==5">
          <div style="margin-bottom:20px;">
            <p class="ant-row title">转出信息</p>
            <div class="ant-row">
              <a-table
                :columns="transferOutcolumn"
                :data-source="transferOut"
                :pagination="false"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
              >
                <span slot="projectName" slot-scope="text,record">
                  <span>{{record.project.name}}</span>
                  <span v-if="record.project_type==1" style="margin-left:5px;">
                    <a-tag color="orange">
                      <span v-if="record.course_type==0">购买</span>
                      <span v-if="record.course_type==1">新报</span>
                      <span v-if="record.course_type==2">续报</span>
                      <span v-if="record.course_type==3">扩科</span>
                    </a-tag>
                  </span>
                </span>
                <span slot="old_orderNo" slot-scope="text,record">
                  <a @click="lookOrder(record.original_order.id)">{{record.original_order.order_no}}</a>
                </span>
                <span slot="unit_price" slot-scope="text,record">
                  <span v-if="record.unit_price">
                    <span v-if="record.price_type==1">{{record.unit_price}}元/课时</span>
                    <span v-if="record.price_type==2">{{record.unit_price}}元/天</span>
                  </span>
                </span>
                <span slot="buy_number" slot-scope="text,record">
                  <span v-if="record.number">
                    <span v-if="record.price_type==1">{{record.number}}课时</span>
                    <span v-if="record.price_type==2">{{record.number}}天</span>
                  </span>
                </span>
                <span slot="give_number" slot-scope="text,record">
                  <span v-if="record.give_number">
                    <span v-if="record.price_type==1">{{record.give_number}}课时</span>
                    <span v-if="record.price_type==2">{{record.give_number}}天</span>
                  </span>
                  <span v-else>
                    <span v-if="record.price_type==1">0课时</span>
                    <span v-if="record.price_type==2">0天</span>
                  </span>
                </span>
                <span slot="other_amount" slot-scope="text,record">
                  ￥{{record.other_amount}}
                  <span v-if="record.other_type==2">（亏损费）</span>
                  <span v-if="record.other_type==1">（手续费）</span>
                </span>
                <span slot="total_amount" slot-scope="text,record">￥{{record.total_amount}}</span>
              </a-table>
            </div>
            <div style="text-align:right;">
              转出合计：
              <span style="color:#ff7519;font-weight: 500;font-size:20px;">￥{{transferoutSum}}</span>
            </div>
          </div>
          <div>
            <p class="ant-row title">转入信息</p>
            <div class="ant-row">
              <a-table
                :columns="transferIncolumn"
                :data-source="transferIn"
                :pagination="false"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
              >
                <span slot="projectName" slot-scope="text,record">
                  <span>{{record.project.name}}</span>
                  <span v-if="record.project_type==1" style="margin-left:5px;">
                    <a-tag color="orange">
                      <span v-if="record.course_type==0">购买</span>
                      <span v-if="record.course_type==1">新报</span>
                      <span v-if="record.course_type==2">续报</span>
                      <span v-if="record.course_type==3">扩科</span>
                    </a-tag>
                  </span>
                </span>
                <span slot="unit_price" slot-scope="text,record">
                  <span v-if="record.project_type==1">
                    <span v-if="record.price_type==1">￥{{record.unit_price}}/课时</span>
                    <span v-if="record.price_type==2">￥{{record.unit_price}}/天</span>
                  </span>
                  <span v-else-if="record.project_type==2">￥{{record.unit_price}}/件</span>
                  <span v-else-if="record.project_type==3">￥{{record.unit_price}}/笔</span>
                </span>
                <span slot="classhours" slot-scope="text,record">
                  <span v-if="record.project_type==1">
                    <span v-if="record.price_type==1">{{record.buy_number}}课时</span>
                    <span
                      v-if="record.price_type==2"
                    >{{record.buy_start_time}}至{{record.buy_end_time}}</span>
                  </span>
                  <span v-else-if="record.project_type==2">{{record.buy_number}}件</span>
                  <span v-else-if="record.project_type==3">{{record.buy_number}}笔</span>
                </span>
                <span slot="courseMoney" slot-scope="text,record">
                  <!-- <span>￥{{record.buy_number*record.unit_price}}</span> -->

                  <span v-if="record.buy_number">
                    ￥{{record.buy_number*record.unit_price}}
                    <!-- <span v-if="record.discount">
                      <span
                        v-if="JSON.parse(record.discount).type==1"
                      >{{Number(record.signing_price)+Number(JSON.parse(record.discount).value)}}</span>
                      <span v-else-if="JSON.parse(record.discount).type==2">
                        {{Number(record.signing_price)/(JSON.parse(record.discount).value/10)}}
                      
                      </span>
                    </span> -->
                  </span>
                  <span v-else>--</span>
                </span>

                <span slot="giveclasshours" slot-scope="text,record">
                  <span v-if="record.project_type==1">
                    <span v-if="record.give_number!=0">
                      <span v-if="record.price_type==1">{{record.give_number}}</span>
                      <span
                        v-else-if="record.price_type==2&&record.give_number!=0"
                      >至{{record.month_buy_end_time}}</span>
                    </span>
                    <span v-else>-</span>
                  </span>

                  <span v-if="record.project_type==2">
                    <span v-if="record.give_number!=0">{{record.give_number}}</span>
                    <span v-else>-</span>
                  </span>

                  <span v-if="record.project_type==3">
                    <span v-if="record.give_number!=0">{{record.give_number}}</span>
                    <span v-else>-</span>
                  </span>
                </span>

                <span slot="moneyDiscount" slot-scope="text,record">
                  <span v-if="record.discount">
                    <span
                    v-if="JSON.parse(record.discount).type==1&&JSON.parse(record.discount).value!=0"
                  >￥{{JSON.parse(record.discount).value}}</span>
                  <span
                    v-else-if="JSON.parse(record.discount).type==2&&JSON.parse(record.discount).value!=0"
                  >{{JSON.parse(record.discount).value?JSON.parse(record.discount).value+'折':'-'}}</span>
                  </span>
                  <span v-else>-</span>
                </span>
                <span slot="signing_price" slot-scope="text,record">
                   <!-- <span v-if="record.signing_price&&record.discount&&JSON.parse(record.discount).value!=0">
                    ￥
                      <span
                        v-if="JSON.parse(record.discount).type==1"
                      >{{Number(record.signing_price)-JSON.parse(record.discount).value}}</span>
                      <span
                        v-else-if="JSON.parse(record.discount).type==2"
                      >{{Number(record.signing_price)*(JSON.parse(record.discount).value/10)}}</span>
                  </span> -->
                  <span v-if="record.signing_price">{{record.signing_price}}</span>
                  <span v-else>-</span>
                </span>
              </a-table>
            </div>
            <div style="text-align:right;">
              转入合计：
              <span style="color:#ff7519;font-weight: 500;font-size:20px;">￥{{transferInSum}}</span>
            </div>
            <div
              style="text-align:right;border-top: 1px solid #e8e8e8; padding-top: 8px;margin-top: 8px;"
              v-if="receiptList.bill_type==2"
            >
              应退金额：
              <span
                style="color:#ff7519;font-weight: 500;font-size:20px;"
              >￥{{transferoutSum-transferInSum}}</span>
            </div>
            <div
              style="text-align:right;border-top: 1px solid #e8e8e8; padding-top: 8px;margin-top: 8px;"
              v-else
            >
              应收金额：
              <span
                style="color:#ff7519;font-weight: 500;font-size:24px;"
              >￥{{Math.abs(transferoutSum-transferInSum)}}</span>
            </div>
          </div>
          <div v-if="receiptList.bill_type==2">
            <p class="ant-row title">退款记录</p>
            <div class="ant-row">
              <a-table
                ref="table"
                :columns="refundColumn"
                :data-source="orderHistory"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
                :pagination="false"
              >
                <span slot="purchase_at" slot-scope="text,record">{{record.purchase_at|dayjs}}</span>
                <span slot="type" slot-scope="text,record">
                  <span v-if="record.type==1">报名/续费</span>
                  <span v-if="record.type==2">手续费</span>
                  <span v-if="record.type==3">补交</span>
                  <span v-if="record.type==4">坏账</span>
                  <span v-if="record.type==5">亏损费</span>
                  <span v-if="record.type==6">转课</span>
                  <span v-if="record.type==7">-</span>
                  <span v-if="record.type==8">退课</span>
                  <span v-if="record.type==9">退物品</span>
                  <span v-if="record.type==10">退费用</span>
                </span>
                <div slot="charge_type" slot-scope="text,record">
                  <div v-if="record.prices!=''">
                    <div v-for="(item,index) in record.prices" :key="index">
                      <div v-if="item.charge_type!=0">
                        <div v-if="item.charge_type==1">支付方式：支付宝</div>
                        <div v-if="item.charge_type==2">支付方式：微信</div>
                        <div v-if="item.charge_type==3">支付方式：现金</div>
                        <div v-if="item.charge_type==4">支付方式：网银</div>
                        <div v-if="item.charge_type==5">支付方式：pos机</div>
                      </div>
                      <div style="margin:5px 0;">退款金额：￥{{item.price}}</div>
                    </div>
                  </div>
                  <div v-else>-</div>
                </div>
                <span slot="status" slot-scope="text,record">
                  <span v-for="(val,index) in record.prices" :key="index">
                    <span v-if="val.bill_type==1">收款成功</span>
                    <span v-if="val.bill_type==2">退款成功</span>
                  </span>
                </span>
              </a-table>
            </div>
          </div>
          <div v-else>
            <p class="ant-row title">支付记录</p>
            <div class="ant-row">
              <a-table
                ref="table"
                :columns="columns1"
                :data-source="orderHistory"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
                :pagination="false"
              >
                <span slot="purchase_at" slot-scope="text,record">{{record.created_at|dayjs}}</span>
                <span slot="type" slot-scope="text,record">
                  <span v-if="record.type==1">报名/续费</span>
                  <span v-if="record.type==2">手续费</span>
                  <span v-if="record.type==3">补交</span>
                  <span v-if="record.type==4">坏账</span>
                  <span v-if="record.type==5">亏损费</span>
                  <span v-if="record.type==6">转课</span>
                  <span v-if="record.type==7">-</span>
                  <span v-if="record.type==8">退课</span>
                  <span v-if="record.type==9">退物品</span>
                  <span v-if="record.type==10">退费用</span>
                </span>
                <div slot="charge_type" slot-scope="text,record">
                  <div v-if="record.prices!=''">
                    <div v-for="(item,index) in record.prices" :key="index">
                      <div v-if="item.charge_type!=0">
                        <div v-if="item.charge_type==1">支付方式：支付宝</div>
                        <div v-if="item.charge_type==2">支付方式：微信</div>
                        <div v-if="item.charge_type==3">支付方式：现金</div>
                        <div v-if="item.charge_type==4">支付方式：网银</div>
                        <div v-if="item.charge_type==5">支付方式：pos机</div>
                      </div>
                      <div style="margin:5px 0;">收款金额：￥{{item.price}}</div>
                    </div>
                  </div>
                  <div v-else>-</div>
                </div>
                <span slot="status" slot-scope="text,record">
                  <span v-for="(val,index) in record.prices" :key="index">
                    <span v-if="val.bill_type==1">收款成功</span>
                    <span v-if="val.bill_type==2">退款成功</span>
                  </span>
                </span>
              </a-table>
            </div>
          </div>
        </div>

        <!-- 退课 -->
        <div v-if="receiptList.order_type==4">
          <div style="margin-bottom:20px;">
            <p class="ant-row title">退课信息</p>
            <div class="ant-row">
              <a-table
                :columns="returncolumn"
                :data-source="returnData"
                :pagination="false"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
              >
                <span slot="old_orderNo" slot-scope="text,record">
                  <a @click="lookOrder(record.original_order.id)">{{record.original_order.order_no}}</a>
                </span>
                <span slot="unit_price" slot-scope="text,record">
                  <span v-if="record.unit_price">
                    <span v-if="record.price_type==1">{{record.unit_price}}元/课时</span>
                    <span v-if="record.price_type==2">{{record.unit_price}}元/天</span>
                  </span>
                </span>
                <span slot="buy_number" slot-scope="text,record">
                  <span v-if="record.number">
                    <span v-if="record.price_type==1">{{record.number}}课时</span>
                    <span v-if="record.price_type==2">{{record.number}}天</span>
                  </span>
                </span>
                <span slot="give_number" slot-scope="text,record">
                  <span v-if="record.give_number">
                    <span v-if="record.price_type==1">{{record.give_number}}课时</span>
                    <span v-if="record.price_type==2">{{record.give_number}}天</span>
                  </span>
                  <span v-else>
                    <span v-if="record.price_type==1">0课时</span>
                    <span v-if="record.price_type==2">0天</span>
                  </span>
                </span>
                <span slot="other_amount" slot-scope="text,record">
                  {{record.other_amount}}
                  <span v-if="record.other_type==2">（亏损费）</span>
                  <span v-if="record.other_type==1">（手续费）</span>
                </span>
                <span slot="total_amount" slot-scope="text,record">￥{{record.total_amount}}</span>
              </a-table>
            </div>
            <div style="text-align:right;">
              应退金额：
              <span
                style="color:#ff7519;font-weight: 500;font-size:20px;"
              >￥{{refundSum.toFixed(2)}}</span>
            </div>
          </div>
          <div>
            <p class="ant-row title">退款记录</p>
            <div class="ant-row">
              <a-table
                ref="table"
                :columns="refundColumn"
                :data-source="orderHistory"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
                :pagination="false"
              >
                <span slot="purchase_at" slot-scope="text,record">{{record.purchase_at|dayjs}}</span>
                <span slot="type" slot-scope="text,record">
                  <span v-if="record.type==1">报名/续费</span>
                  <span v-if="record.type==2">手续费</span>
                  <span v-if="record.type==3">补交</span>
                  <span v-if="record.type==4">坏账</span>
                  <span v-if="record.type==5">亏损费</span>
                  <span v-if="record.type==6">转课</span>
                  <span v-if="record.type==7">-</span>
                  <span v-if="record.type==8">退课</span>
                  <span v-if="record.type==9">退物品</span>
                  <span v-if="record.type==10">退费用</span>
                </span>
                <div slot="charge_type" slot-scope="text,record">
                  <div v-for="(item,index) in record.prices" :key="index">
                    <div v-if="item.charge_type!=0">
                      <div v-if="item.charge_type==1">支付方式：支付宝</div>
                      <div v-if="item.charge_type==2">支付方式：微信</div>
                      <div v-if="item.charge_type==3">支付方式：现金</div>
                      <div v-if="item.charge_type==4">支付方式：网银</div>
                      <div v-if="item.charge_type==5">支付方式：pos机</div>
                    </div>
                    <div style="margin:5px 0;">退款金额：￥{{item.price}}</div>
                  </div>
                </div>
                <span slot="status" slot-scope="text,record">
                  <span v-for="(val,index) in record.prices" :key="index">
                    <span v-if="val.bill_type==1">收款成功</span>
                    <span v-if="val.bill_type==2">退款成功</span>
                  </span>
                </span>
              </a-table>
            </div>
          </div>
        </div>
        <!-- 退物品 -->
        <div v-if="receiptList.order_type==3">
          <div style="margin-bottom:20px;">
            <p class="ant-row title">退物品信息</p>
            <div class="ant-row">
              <a-table
                :columns="returnGoodscolumn"
                :data-source="returnData"
                :pagination="false"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
              >
                <span slot="old_orderNo" slot-scope="text,record">
                  <a @click="lookOrder(record.original_order.id)">{{record.original_order.order_no}}</a>
                </span>
                <span slot="unit_price" slot-scope="text,record">
                  <span v-if="record.unit_price">{{record.unit_price}}元/件</span>
                </span>
                <span slot="return_number" slot-scope="text,record">
                  <span v-if="record.number">{{record.number}}/件</span>
                </span>
                <span slot="money" slot-scope="text,record">￥{{record.total_amount}}</span>
                <span slot="other_amount" slot-scope="text,record">
                  ￥{{record.other_amount}}
                  <span v-if="record.other_type==2">（亏损费）</span>
                  <span v-if="record.other_type==1">（手续费）</span>
                </span>
                <span slot="is_return_warehouse" slot-scope="text,record">
                  <span v-if="record.is_return_warehouse">{{record.is_return_warehouse==1?'是':'否'}}</span>
                </span>
              </a-table>
            </div>
            <div style="text-align:right;">
              应退金额：
              <span
                style="color:#ff7519;font-weight: 500;font-size:20px;"
              >￥{{refundSum.toFixed(2)}}</span>
            </div>
          </div>
          <div>
            <p class="ant-row title">退款记录</p>
            <div class="ant-row">
              <a-table
                ref="table"
                :columns="refundColumn"
                :data-source="orderHistory"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
                :pagination="false"
              >
                <span slot="purchase_at" slot-scope="text,record">{{record.purchase_at|dayjs}}</span>
                <span slot="type" slot-scope="text,record">
                  <span v-if="record.type==1">报名/续费</span>
                  <span v-if="record.type==2">手续费</span>
                  <span v-if="record.type==3">补交</span>
                  <span v-if="record.type==4">坏账</span>
                  <span v-if="record.type==5">亏损费</span>
                  <span v-if="record.type==6">转课</span>
                  <span v-if="record.type==7">-</span>
                  <span v-if="record.type==8">退课</span>
                  <span v-if="record.type==9">退物品</span>
                  <span v-if="record.type==10">退费用</span>
                </span>
                <div slot="charge_type" slot-scope="text,record">
                  <div v-for="(item,index) in record.prices" :key="index">
                    <div v-if="item.charge_type!=0">
                      <div v-if="item.charge_type==1">支付方式：支付宝</div>
                      <div v-if="item.charge_type==2">支付方式：微信</div>
                      <div v-if="item.charge_type==3">支付方式：现金</div>
                      <div v-if="item.charge_type==4">支付方式：网银</div>
                      <div v-if="item.charge_type==5">支付方式：pos机</div>
                    </div>
                    <div style="margin:5px 0;">退款金额：￥{{item.price}}</div>
                  </div>
                </div>
                <span slot="status" slot-scope="text,record">
                  <span v-for="(val,index) in record.prices" :key="index">
                    <span v-if="val.bill_type==1">收款成功</span>
                    <span v-if="val.bill_type==2">退款成功</span>
                  </span>
                </span>
              </a-table>
            </div>
          </div>
        </div>
        <!-- 退费用 -->
        <div v-if="receiptList.order_type==2">
          <div style="margin-bottom:20px;">
            <p class="ant-row title">退费用信息</p>
            <div class="ant-row">
              <a-table
                :columns="returnCostcolumn"
                :data-source="returnData"
                :pagination="false"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
              >
                <span slot="old_orderNo" slot-scope="text,record">
                  <a @click="lookOrder(record.original_order.id)">{{record.original_order.order_no}}</a>
                </span>
                <span slot="unit_price" slot-scope="text,record">
                  <span v-if="record.unit_price">{{record.unit_price}}元/件</span>
                </span>
                <span slot="return_number" slot-scope="text,record">
                  <span v-if="record.number">{{record.number}}/件</span>
                </span>
                <span slot="money" slot-scope="text,record">￥{{record.total_amount}}</span>
                <span slot="other_amount" slot-scope="text,record">
                  ￥{{record.other_amount}}
                  <span v-if="record.other_type==2">（亏损费）</span>
                  <span v-if="record.other_type==1">（手续费）</span>
                </span>
                <!-- <span slot="is_return_warehouse" slot-scope="text,record">
                  <span v-if="record.is_return_warehouse">{{record.is_return_warehouse==1?'是':'否'}}</span>
                </span>-->
              </a-table>
            </div>
            <div style="text-align:right;">
              应退金额：
              <span
                style="color:#ff7519;font-weight: 500;font-size:20px;"
              >￥{{refundSum.toFixed(2)}}</span>
            </div>
          </div>
          <div>
            <p class="ant-row title">退款记录</p>
            <div class="ant-row">
              <a-table
                ref="table"
                :columns="refundColumn"
                :data-source="orderHistory"
                class="user_management_table"
                style="border:1px solid #e8e8e8"
                :pagination="false"
              >
                <span slot="purchase_at" slot-scope="text,record">{{record.purchase_at|dayjs}}</span>
                <span slot="type" slot-scope="text,record">
                  <span v-if="record.type==1">报名/续费</span>
                  <span v-if="record.type==2">手续费</span>
                  <span v-if="record.type==3">补交</span>
                  <span v-if="record.type==4">坏账</span>
                  <span v-if="record.type==5">亏损费</span>
                  <span v-if="record.type==6">转课</span>
                  <span v-if="record.type==7">-</span>
                  <span v-if="record.type==8">退课</span>
                  <span v-if="record.type==9">退物品</span>
                  <span v-if="record.type==10">退费用</span>
                </span>
                <div slot="charge_type" slot-scope="text,record">
                  <div v-for="(item,index) in record.prices" :key="index">
                    <div v-if="item.charge_type!=0">
                      <div v-if="item.charge_type==1">支付方式：支付宝</div>
                      <div v-if="item.charge_type==2">支付方式：微信</div>
                      <div v-if="item.charge_type==3">支付方式：现金</div>
                      <div v-if="item.charge_type==4">支付方式：网银</div>
                      <div v-if="item.charge_type==5">支付方式：pos机</div>
                    </div>
                    <div style="margin:5px 0;">退款金额：￥{{item.price}}</div>
                  </div>
                </div>
                <span slot="status" slot-scope="text,record">
                  <span v-for="(val,index) in record.prices" :key="index">
                    <span v-if="val.bill_type==1">收款成功</span>
                    <span v-if="val.bill_type==2">退款成功</span>
                  </span>
                </span>
              </a-table>
            </div>
          </div>
        </div>
      </a-card>
      <!-- 补交 -->
      <after-pay ref="payed" @update="updateRefresh"></after-pay>
      <a-modal
        title="作废订单"
        :visible="voidOrder_visible"
        :confirm-loading="voidOrder_confirmLoading"
        @ok="voidOrder_handleOk('voidOrder_ruleForm')"
        @cancel="voidOrder_handleCancel"
        cancelText="取消"
        okText="作废"
        width="550px"
      >
        <!-- :confirm-loading="voidOrder_confirmLoading" -->
        <a-alert type="info" :message="voidOrder_description" class="a-alert" banner />
        <a-form-model
          style="margin-top:20px;"
          ref="voidOrder_ruleForm"
          :model="voidOrderData"
          :rules="voidOrder_rules"
          :label-col="{span: 4 }"
          :wrapper-col="{span: 14}"
        >
          <a-form-model-item label="作废类型" prop="type">
            <a-select placeholder="请选择作废类型" v-model="voidOrderData.type">
              <a-select-option value="1">重复录入</a-select-option>
              <a-select-option value="2">信息填错</a-select-option>
              <a-select-option value="3">其他</a-select-option>
            </a-select>
          </a-form-model-item>
          <a-form-model-item label="作废原因">
            <a-input type="textarea" v-model="voidOrderData.reason" />
          </a-form-model-item>
        </a-form-model>
      </a-modal>
    </a-spin>
  </div>
</template>

<script>
import topNavBar from '@/components/topNavBar/topNavBar'
import afterPay from '@/components/afterPay'

import { STable } from '@/components'
import { orderdetails, makeup, abolishcontract, orderedit, logs } from '@/api/order'
import { accountList } from '@/api/account'

import moment from 'moment'
export default {
  name: 'orderdetails',
  components: {
    STable,
    topNavBar,
    afterPay,
  },

  data() {
    return {
      //作废订单
      voidOrderData: {
        type: undefined,
        reason: undefined,
      },
      voidOrder_rules: {
        type: [{ required: true, message: '请选择', trigger: 'change' }],
      },
      voidOrder_visible: false,
      voidOrder_confirmLoading: false,
      voidOrder_description:
        '学员信息录错可在学员详情页修改，业绩归属人、备注录错可在订单详情页直接修改，无需进行作废订单操作。',
      //
      tableloading: false,
      pagination: {
        total: 0,
        pageSize: 10, //每页中显示10条数据
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '50', '100'], //每页中显示的数据
        showTotal: (total) => `共有 ${total} 条数据`, //分页中显示总的数据
      },
      queryParam: {
        pageNo: 1, //第几页
        pageSize: 10, //每页中显示数据的条数
      },
      acitonColumns: [
        {
          title: '操作时间',
          scopedSlots: { customRender: 'updated_at' },
        },
        {
          title: '操作人',
          dataIndex: 'operator_name',
        },
        {
          title: '修改事件',
          dataIndex: 'event',
        },
        {
          title: '修改内容',
          dataIndex: 'content',
          scopedSlots: { customRender: 'content' },
          // width:150,
          // ellipsis:true
        },
      ],
      actionData: [],
      action_confirmLoading: false,
      action_visible: false,
      newremarks: null,
      userSelect: [],
      user_ids: [],
      remarks: '',
      description: '修改业绩归属人，业绩将归属新的归属人。',
      user_name_visible: false,
      user_name_confirmLoading: false,
      remarks_visible: false,
      remarks_confirmLoading: false,
      loading: false,
      printtitle: this.$route.meta.title,
      showindex: [false, false, false, false, false],
      relprice: '',
      ischecked: false,
      inputprice: [0, 0, 0, 0, 0],
      //弹出层
      visible: false,
      confirmLoading: false,
      //提交数据
      form: {
        real_price_arr: [],
        // user_id: null,
        purchase_at: '',
        real_price: 0,
        receivable: null,
        operator: this.$store.state.user.name,
      },
      real_price: '',
      labelCol: { span: 7 },
      wrapperCol: { span: 14 },
      //收款
      data: [
        {
          title: null,
        },
      ],
      shopList: [],
      columns: [
        {
          title: '购买项目',
          dataIndex: 'projectName',
          scopedSlots: { customRender: 'projectName' },
        },
        {
          title: '定价标准',
          scopedSlots: { customRender: 'unit_price' },
        },
        {
          title: '购买数量',
          scopedSlots: { customRender: 'classhours' },
        },

        {
          title: '原价',
          scopedSlots: { customRender: 'courseMoney' },
        },

        {
          title: '赠送数量',
          scopedSlots: { customRender: 'giveclasshours' },
        },
        {
          title: '直减/折扣',
          scopedSlots: { customRender: 'moneyDiscount' },
        },

        {
          title: '小计',
          scopedSlots: { customRender: 'signing_price' },
        },
      ],
      orderHistory: [],
      columns1: [
        {
          title: '支付时间',
          scopedSlots: { customRender: 'purchase_at' },
        },
        {
          title: '经办人',
          dataIndex: 'operator',
        },
        {
          title: '项目',
          scopedSlots: { customRender: 'type' },
        },
        {
          title: '收款方式/金额',
          scopedSlots: { customRender: 'charge_type' },
        },

        {
          title: '状态',
          scopedSlots: { customRender: 'status' },
        },
      ],
      refundColumn: [
        {
          title: '退款时间',
          scopedSlots: { customRender: 'purchase_at' },
        },
        {
          title: '经办人',
          dataIndex: 'operator',
        },
        {
          title: '项目',
          scopedSlots: { customRender: 'type' },
        },
        {
          title: '收款方式/金额',
          scopedSlots: { customRender: 'charge_type' },
        },

        {
          title: '状态',
          scopedSlots: { customRender: 'status' },
        },
      ],
      receiptList: {
        student: null,
        receivable: null,
        purchase_at: null,
        user: null,
        operator: null,
        user_name: null,
        remarks: null,
      },
      voidLog: [],
      voidLog_columns: [
        {
          title: '作废时间',
          // dataIndex: 'tags',
          scopedSlots: { customRender: 'created_at' },
          width: 400,
        },
        {
          title: '作废人',
          dataIndex: 'user_school.name',
          width: 400,
          // scopedSlots: { customRender: 'created_at' },
        },
        {
          title: '作废类型',
          scopedSlots: { customRender: 'type' },
          width: 400,
        },
        {
          title: '作废原因',
          dataIndex: 'reason',
          width: 400,
          ellipsis: true,
        },
      ],
      transferOut: [],
      transferOutcolumn: [
        {
          title: '转出课程',
          scopedSlots: { customRender: 'projectName' },
          // dataIndex: 'project.name',
        },
        {
          title: '原订单号',
          scopedSlots: { customRender: 'old_orderNo' },
          // dataIndex: 'original_order.order_no',
        },
        {
          title: '单价',
          scopedSlots: { customRender: 'unit_price' },
          // dataIndex: 'operator',
        },
        {
          title: '转出购买数量',
          scopedSlots: { customRender: 'buy_number' },
          // dataIndex: 'number',
        },
        {
          title: '转出赠送数量',
          scopedSlots: { customRender: 'give_number' },
          // dataIndex: 'give_number',
        },
        {
          title: '手续费/亏损费 ',
          scopedSlots: { customRender: 'other_amount' },
          dataIndex: 'other_amount',
        },
        {
          title: '转出金额',
          scopedSlots: { customRender: 'total_amount' },
          // dataIndex: 'operator',
        },
      ],
      transferoutSum: 0,
      transferIn: [],
      transferIncolumn: [
        {
          title: '购买项目',
          // dataIndex: 'project.name',
           scopedSlots: { customRender: 'projectName' },
        },
        {
          title: '定价标准',
          scopedSlots: { customRender: 'unit_price' },
        },
        {
          title: '购买数量',
          scopedSlots: { customRender: 'classhours' },
        },
        {
          title: '总价',
          scopedSlots: { customRender: 'courseMoney' },
        },

        {
          title: '赠送数量',
          scopedSlots: { customRender: 'giveclasshours' },
        },
        {
          title: '直减/折扣',
          scopedSlots: { customRender: 'moneyDiscount' },
        },

        {
          title: '小计',
          scopedSlots: { customRender: 'signing_price' },
        },
      ],
      transferInSum: 0,
      // 退课 退物品 退费用
      returnData: [],
      refundSum: 0,
      returncolumn: [
        {
          title: '退出课程',
          // scopedSlots: { customRender: 'purchase_at' },
          dataIndex: 'project.name',
        },
        {
          title: '原订单号',
          scopedSlots: { customRender: 'old_orderNo' },
          // dataIndex: 'order.order_no',
        },
        {
          title: '单价',
          scopedSlots: { customRender: 'unit_price' },
        },
        {
          title: '退出购买数量',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'buy_number' },
        },
        {
          title: '退出赠送数量',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'give_number' },
        },
        {
          title: '手续费/亏损费',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'other_amount' },
        },
        {
          title: '退出金额',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'total_amount' },
        },
      ],
      returnGoodscolumn: [
        {
          title: '退出物品',
          // scopedSlots: { customRender: 'purchase_at' },
          dataIndex: 'project.name',
        },
        {
          title: '原订单号',
          scopedSlots: { customRender: 'old_orderNo' },
          // dataIndex: 'order.order_no',
        },
        {
          title: '单价',
          scopedSlots: { customRender: 'unit_price' },
        },
        {
          title: '退出数量',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'return_number' },
        },
        {
          title: '退出金额',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'money' },
        },
        {
          title: '手续费/亏损费',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'other_amount' },
        },
        {
          title: '是否退回仓库',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'is_return_warehouse' },
        },
      ],
      returnCostcolumn: [
        {
          title: '退出物品',
          // scopedSlots: { customRender: 'purchase_at' },
          dataIndex: 'project.name',
        },
        {
          title: '原订单号',
          scopedSlots: { customRender: 'old_orderNo' },
          // dataIndex: 'order.order_no',
        },
        {
          title: '单价',
          scopedSlots: { customRender: 'unit_price' },
        },
        {
          title: '退出数量',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'return_number' },
        },
        {
          title: '退出金额',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'money' },
        },
        {
          title: '手续费/亏损费',
          // scopedSlots: { customRender: 'purchase_at' },
          scopedSlots: { customRender: 'other_amount' },
        },
      ],
    }
  },

  created() {
    this.refresh()
  },

  methods: {
    //查看原订单
    lookOrder(id) {
      this.$router.push({
        name: 'orderdetails',
        query: {
          id: id,
        },
      })
    },
    refresh() {
      this.form.purchase_at = moment(this.today).format('YYYY-MM-DD HH:mm:ss')
      this.getTable()
      //获取当前的时间
      let date = new Date()
      this.todatime = date.toLocaleString()
      accountList({ pageSize: 999999, school_id: this.$store.state.user.school }).then((res) => {
        this.userSelect = res.data
      })
    },
    actionCanl() {
      this.action_visible = false
    },
    actionDay(id) {
      this.actionlogs(id)
      this.action_visible = true
    },
    actionlogs(id) {
      this.tableloading = true
      logs(this.queryParam, id)
        .then((res) => {
          const pagination = { ...this.pagination }
          pagination.total = res.meta.pagination.total
          this.actionData = res.data
          this.pagination = pagination
        })
        .finally(() => {
          this.tableloading = false
        })
        .catch((err) => {
          this.$message.error(err.data.message || '日志数据获取失败')
        })
    },
    handleTableChange(pagination) {
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize

      this.queryParam.pageNo = pagination.current
      this.queryParam.pageSize = pagination.pageSize
      this.actionlogs(this.receiptList.id)
    },
    //&业绩归属人1
    //编辑备注2
    remarksEdit() {
      if (this.receiptList.remarks) {
        this.newremarks = JSON.parse(JSON.stringify(this.receiptList.remarks))
      }
      this.remarks_visible = true
    },
    user_name_remarks(type) {
      this.remarks_confirmLoading = true
      let obj = {}
      type == 1 ? (obj = { user_ids: this.user_ids }) : (obj = { remarks: this.newremarks })

      orderedit(obj, this.receiptList.id)
        .then((res) => {
          this.getTable()
          this.$message.success('修改成功')
        })
        .finally(() => {
          this.remarks_confirmLoading = this.remarks_visible = this.user_name_visible = false
        })
        .catch((err) => {
          this.$message.error(err.data.message || '修改失败')
        })
    },

    getTable() {
      this.loading = true
      orderdetails(this.$route.query.id)
        .then((res) => {
          if (res.voidLog) {
            this.voidLog = [res.voidLog]
          }
          if (res.order_type == 1) {
            this.shopList = res.orderContent
            this.orderHistory = res.orderHistory
          }
          if (res.order_type == 5) {
            //转出
            this.transferOut = res.refunds
            //转入
            this.transferIn = res.orderContent
            //退款
            this.orderHistory = res.orderHistory
            this.transferInSum = 0
            this.transferoutSum = 0
            res.orderContent.forEach((item) => {
              this.transferInSum = this.transferInSum + Number(item.signing_price)
            })
            res.refunds.forEach((item) => {
              this.transferoutSum = this.transferoutSum + Number(item.total_amount)
            })
          }
          if (res.order_type == 2 || res.order_type == 3 || res.order_type == 4) {
            this.returnData = res.refunds
            this.refundSum = 0
            this.returnData.forEach((item) => {
              this.refundSum = this.refundSum + Number(item.total_amount)
            })
            this.orderHistory = res.orderHistory
          }
          this.receiptList = res
          this.user_ids = []
          res.user.forEach((val) => {
            this.user_ids.push(val.id)
          })
          this.data[0].title = '收据编号:' + res.order_no
        })
        .finally(() => {
          this.loading = false
        })
        .catch((err) => {
          this.$message.error(err.data.message || '获取订单详情失败')
        })
    },

    //弹出层
    showModal(res) {
      this.$refs.payed.showModal(this.receiptList)
    },
    updateRefresh() {
      this.getTable()
    },

    moment,
    onChange(date, dateString) {
      this.form.purchase_at = dateString
    },
    formatTime(e) {
      let date
      if (e) {
        date = new Date(e)
      } else {
        date = new Date()
      }
      let seperator1 = '-'
      let year = date.getFullYear()
      let month = date.getMonth() + 1
      let strDate = date.getDate()
      if (month >= 1 && month <= 9) {
        month = '0' + month
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
      }
      let today = year + seperator1 + month + seperator1 + strDate
      return today
    },
    //废除合同
    voidOrder_handleOk(formName) {
      this.voidOrder_confirmLoading = true
      this.$refs[formName].validate((valid) => {
        if (valid) {
          abolishcontract(this.voidOrderData, Number(this.$route.query.id)).then((res) => {
            // this.$forceUpdate()
            this.voidOrder_visible = false
            this.voidOrder_confirmLoading = false
            this.refresh()
          }).catch(err=>{
            if(err.data&&err.data.message){
              this.$message.error(err.data.message)
            }else{
              this.$message.error('操作失败，请重试~')
            }
          })
        } else {
          console.log('error submit!!')
          this.voidOrder_confirmLoading = false
          return false
        }
      })
    },
    voidOrder_handleCancel() {
      this.voidOrder_visible = false
    },
    showDeleteConfirm(id) {
      this.voidOrder_visible = true
    },
    goreceipt() {
      this.$router.push({
        name: 'receipt',
        query: {
          id: this.$route.query.id,
        },
      })
    },

    //标记为坏账
    badorder(e) {
      let that = this
      let sendData = {}
      let timer = ''
      timer = moment().format('YYYY-MM-DD HH:mm:ss')

      sendData.real_price_arr = [
        {
          real_price: 0,
          charge_type: 1,
        },
      ]
      sendData.purchase_at = timer
      sendData.receivable = (e.receivable * 1000000 - e.real_price * 1000000) / 1000000
      sendData.choose_loss = '1'

      that.$confirm({
        title: '你确定要标为坏账吗',
        content: '标记为坏账后，此订单不再欠费并变为“已支付”，不影响课程课时',
        okText: '确定标记为坏账',
        cancelText: '取消',
        onOk() {
          makeup(sendData, that.$route.query.id)
            .then((res) => {
              that.refresh()
            })
            .catch((err) => {})
        },
        onCancel() {
          console.log('Cancel')
        },
      })
    },
    //返回上一级
    back() {
      this.$router.go(-1)
    },
  },
  watch: {
    '$route.query.id': {
      handler() {
        this.refresh()
      },
      deep: true,
    },
    btnStyle: {
      handler(val) {
        let num = 0
        val.forEach((item) => {
          if (item.check == true) {
            num = num + Number(item.price)
          }
        })
        this.form.real_price = num.toFixed(2)
      },
      deep: true,
    },
  },
}
</script>

<style lang="less" scoped>
// @import '~@/components/index.less';
.retu {
  cursor: pointer;
}
.retu:hover {
  color: #1890ff;
}
.basic-item {
  padding-left: 16px;
  p {
    display: flex;
    .achievement {
      max-width: 300px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .leave-msg {
      word-break: break-all;
      max-width: 300px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
.title {
  color: #333;
  font-weight: 500;
}
.makebox {
  display: flex;
  align-items: center;
}
.paymethod {
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  padding: 0 10px;
  margin-right: 6px;
  text-align: center;
  height: 30px;
  line-height: 30px;

  cursor: pointer;
  /* width: 50px; */
}
.active {
  border: 1px solid #1890ff;
}
.isshow {
  margin-right: 15px;
}
.loss {
  color: #1890ff;
}
.paybigbox {
  display: flex;
  margin-left: 60px;
  flex-wrap: wrap;
}
.other-pay-type {
  margin-right: 12px;
  margin-bottom: 8px;
  width: 270px;
  display: inline-table;
}
.pay-type-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 12px;
  width: 270px;
  height: 40px;
  box-sizing: border-box;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
}
#inputNumber {
  outline: none;
}

.order-info span {
  padding-right: 20px;
}
.edit-btn {
  padding-left: 10px;
  cursor: pointer;
}
.textarea_remark {
  width: 100%;
  height: 80px;
  border-radius: 5px;
}

.a-alert {
  border: none;
  border-radius: 5px;
  margin-top: -10px;
}
</style>